using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

/* 
----------------------------------------------------------------------------
【调试程序工具栏】

1、DiguaDebug.Instance.Button("按钮1", doSomething);
水平生成一个按钮，用于调试doSomething()方法用的。

----------------------------------------------------------------------------
 */
public class DiguaDebug : MonoBehaviour
{

    // -----------------------实例化 START----------------------
    private static DiguaDebug temp;

    public static DiguaDebug Instance
    {
        get
        {
            if (temp == null)
            {
                temp = FindObjectOfType<DiguaDebug>();

                if (temp == null) temp = new GameObject("DiguaDebug").AddComponent<DiguaDebug>();

            }

            return temp;
        }
    }
    // -----------------------实例化 END----------------------

    public bool isShowBtn = false;

    private float mX;

    private float mY;

    private UnityAction mAction;

    private List<MyButton> myButtonList = new List<MyButton>();

    void OnGUI()
    {
        // 默认水平排
        int i = 0;
        float buttonWidth = 100;
        float buttonHeight = 50;
        foreach (var item in myButtonList)
        {
            if (GUI.Button(new Rect(50 + i * buttonWidth, 50, buttonWidth, buttonHeight), item.mTitle))
            {
                item.mAction();
            }
            i++;
        }

    }

    public void Button(string title, Action action)
    {
        MyButton myButton = new MyButton();
        myButton.isShowBtn = true;
        myButton.mAction = action;
        myButton.mTitle = title;

        myButtonList.Add(myButton);
    }

    class MyButton
    {
        public bool isShowBtn;
        public float mX;
        public float mY;
        public Action mAction;
        public string mTitle;
    }

}
